#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-08-14 2:09 下午
# @Author  : yangdy
# @File    : 2020-08-14.20.有效的括号
# @Software: PyCharmCE
from tools.my_methods import *


class Solution:
    def isValid(self, s: str) -> bool:
        stack, ss = [], {'()', '[]', '{}'}
        for si in s:
            if si in '([{':
                stack.append(si)
            elif si in ')]}':
                if not stack or stack.pop()+si not in ss:
                    return False
        if stack:
            return False
        return True


questions = [
    ('()',),
    ('()[]{}',),
    ('(]',),
    ('([)]',),
    ('{[]}',),
    ('[',),
]

work(questions, lambda q: Solution().isValid(q[0]))

